package study.java.thread06;

/**
* @Name: SetStudentRunnable
* @Description: 生产学生数据类
* @Author: 李超	lc_jack@foxmail.com
* @CreateDate: 2017-1-9 下午4:52:48 
* @Version: V1.0
 */
public class SetStudentRunnable implements Runnable {
	
	private Student student ;
	private int x = 0 ;

	public SetStudentRunnable(Student student) {
		this.student = student;
	}

	@Override
	public void run() {
		while(true) {
			synchronized (student) {
				//判断是否有数据
				if(student.getFlag()) {
					//如果有数据，等待，等待消费者消费数据
					try {
						student.wait() ;
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
				}
				//生产数据
				if(x % 2 == 0) {
					student.setName("张三") ;
					student.setAge(21) ;
				} else {
					student.setName("李四") ;
					student.setAge(23) ;
				}
				x++ ;
				//生产完数据之后，修改标记
				student.setFlag(true) ;
				//唤醒线程
				student.notify() ;
			}
		}
	}
	
	

}
